<template>
	<view class="container">
		<!-- 状态栏 -->
		<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
		
		<!-- 导航栏 -->
		<view class="nav-bar">
			<view class="nav-left" @click="goBack">
				<image src="/static/icons/back.png" mode="aspectFit" class="back-icon"></image>
			</view>
			<view class="nav-title">网赚游戏</view>
		</view>
		
		<!-- 用户信息 -->
		<view class="user-info animate__animated animate__fadeIn">
			<view class="balance-box">
				<view class="balance-header">
					<view class="balance-title">当前余额</view>
					<text class="icon">💰</text>
				</view>
				<view class="balance-amount">¥ {{userBalance}}</view>
				<view class="balance-btns">
					<button class="btn withdraw" @click="goToWithdraw">
						<text class="icon">⬇️</text>
						<text>提现</text>
					</button>
					<button class="btn recharge" @click="goToRecharge">
						<text class="icon">⬆️</text>
						<text>充值</text>
					</button>
				</view>
			</view>
		</view>
		
		<!-- 游戏列表 -->
		<view class="game-section">
			<view class="section-title">
				<text class="title-text">推荐游戏</text>
				<text class="title-desc">玩游戏赚现金</text>
			</view>
			<view class="game-list">
				<view 
					class="game-item animate__animated animate__fadeInUp" 
					v-for="(game, index) in games" 
					:key="index" 
					@click="startGame(game)"
					:style="{'animation-delay': index * 0.1 + 's'}"
				>
					<view class="game-content">
						<image :src="game.icon" mode="aspectFill" class="game-icon"></image>
						<view class="game-info">
							<view class="game-name">{{game.name}}</view>
							<view class="game-desc">{{game.desc}}</view>
							<view class="game-reward">
								<text class="icon">🎁</text>
								<text>{{game.reward}}</text>
							</view>
						</view>
						<view class="game-players">
							<view class="player-count">
								<text class="icon">👤</text>
								<text>{{game.players}}人在玩</text>
							</view>
							<text class="icon">▶️</text>
						</view>
					</view>
					<view class="game-progress-bg">
						<view class="game-progress" :style="{ width: getRandomProgress() + '%' }"></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			statusBarHeight: 0,
			userBalance: 0.00,
			games: [
				{
					name: '看视频赚钱',
					desc: '观看视频领取奖励',
					icon: '/static/game/video.png',
					reward: '最高1元/次',
					players: 2893,
					path: '/pages/money-game/video'
				},
				{
					name: '每日签到',
					desc: '连续签到奖励翻倍',
					icon: '/static/game/signin.png',
					reward: '最高2元/天',
					players: 5271,
					path: '/pages/money-game/signin'
				},
				{
					name: '幸运大转盘',
					desc: '免费抽奖赢大奖',
					icon: '/static/game/wheel.png',
					reward: '最高5元/次',
					players: 1562,
					path: '/pages/money-game/wheel'
				},
				{
					name: '拼图游戏',
					desc: '完成拼图赢奖励',
					icon: '/static/game/puzzle.png',
					reward: '最高3元/局',
					players: 986,
					path: '/pages/money-game/puzzle'
				}
			]
		}
	},
	onLoad() {
		// 获取状态栏高度
		this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
		
		// 获取用户余额
		this.getUserBalance();
	},
	methods: {
		// 返回上一页
		goBack() {
			uni.navigateBack();
		},
		
		// 获取用户余额
		getUserBalance() {
			// TODO: 调用API获取用户余额
			this.userBalance = 5.20;
		},
		
		// 开始游戏
		startGame(game) {
			uni.navigateTo({
				url: game.path
			});
		},
		
		// 跳转到提现页面
		goToWithdraw() {
			uni.navigateTo({
				url: '/pages/money-game/withdraw'
			});
		},
		
		// 跳转到充值页面
		goToRecharge() {
			uni.navigateTo({
				url: '/pages/money-game/recharge'
			});
		},
		
		getRandomProgress() {
			return Math.floor(Math.random() * 40) + 60;
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	min-height: 100vh;
	background-color: #f8f9fa;
}

.status-bar {
	background: linear-gradient(135deg, #ff6b6b, #ff8787);
}

.nav-bar {
	display: flex;
	align-items: center;
	height: 44px;
	background: linear-gradient(135deg, #ff6b6b, #ff8787);
	padding: 0 15px;
}

.nav-left {
	width: 40px;
	height: 100%;
	display: flex;
	align-items: center;
}

.back-icon {
	width: 20px;
	height: 20px;
	filter: brightness(0) invert(1);
}

.nav-title {
	flex: 1;
	text-align: center;
	font-size: 16px;
	font-weight: 500;
	color: #ffffff;
}

.user-info {
	padding: 15px;
	margin-bottom: 10px;
}

.balance-box {
	background: linear-gradient(135deg, #ffffff, #f8f9fa);
	border-radius: 16px;
	padding: 20px;
	box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.balance-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.balance-title {
	font-size: 14px;
	color: #666666;
}

.balance-amount {
	font-size: 36px;
	font-weight: bold;
	margin: 15px 0;
	background: linear-gradient(135deg, #ff6b6b, #ff8787);
	-webkit-background-clip: text;
	color: transparent;
}

.balance-btns {
	display: flex;
	gap: 20rpx;
	margin-top: 20rpx;
	
	.btn {
		flex: 1;
		height: 80rpx;
		border-radius: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 10rpx;
		border: none;
		
		&.withdraw {
			background: linear-gradient(to right, #ff6b6b, #ff8787);
			color: #ffffff;
		}
		
		&.recharge {
			background: linear-gradient(to right, #4ecdc4, #45b7af);
			color: #ffffff;
		}
		
		text {
			font-size: 28rpx;
		}
		
		&:active {
			opacity: 0.8;
		}
	}
}

.game-section {
	padding: 0 15px;
}

.section-title {
	margin-bottom: 15px;
	display: flex;
	align-items: center;
	gap: 10px;
}

.title-text {
	font-size: 18px;
	font-weight: bold;
	color: #333333;
}

.title-desc {
	font-size: 12px;
	color: #999999;
	background-color: #f1f3f5;
	padding: 2px 8px;
	border-radius: 10px;
}

.game-list {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.game-item {
	background-color: #ffffff;
	border-radius: 16px;
	overflow: hidden;
	box-shadow: 0 2px 8px rgba(0,0,0,0.05);
	transition: all 0.3s ease;
}

.game-item:active {
	transform: scale(0.98);
}

.game-content {
	padding: 15px;
	display: flex;
	align-items: center;
}

.game-icon {
	width: 60px;
	height: 60px;
	border-radius: 12px;
	margin-right: 15px;
	box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.game-info {
	flex: 1;
}

.game-name {
	font-size: 16px;
	font-weight: 500;
	margin-bottom: 5px;
	color: #333333;
}

.game-desc {
	font-size: 13px;
	color: #666666;
	margin: 5px 0;
}

.game-reward {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 13px;
	color: #ff6b6b;
}

.game-players {
	display: flex;
	align-items: center;
	gap: 5px;
}

.player-count {
	display: flex;
	align-items: center;
	gap: 3px;
	font-size: 12px;
	color: #999999;
}

.game-progress-bg {
	height: 4px;
	background-color: #f1f3f5;
}

.game-progress {
	height: 100%;
	background: linear-gradient(90deg, #ff6b6b, #ff8787);
	border-radius: 2px;
	transition: width 0.3s ease;
}

/* 动画类 */
.animate__animated {
	animation-duration: 0.5s;
}

@keyframes fadeIn {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes fadeInUp {
	from {
		opacity: 0;
		transform: translateY(20px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@keyframes zoomIn {
	from {
		opacity: 0;
		transform: scale(0.9);
	}
	to {
		opacity: 1;
		transform: scale(1);
	}
}

.icon {
	font-size: 20px;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.balance-header {
	.icon {
		font-size: 24px;
	}
}

.balance-btns {
	.icon {
		font-size: 16px;
		margin-right: 4px;
	}
}

.game-reward {
	.icon {
		font-size: 14px;
	}
}

.game-players {
	.icon {
		font-size: 12px;
		
		&:last-child {
			font-size: 16px;
		}
	}
}
</style> 